package com.moehu.back.controller.admin;

import com.moehu.back.annotation.AdminRestController;
import com.moehu.back.annotation.UserLoginToken;
import com.moehu.back.model.OpusModel;
import com.moehu.back.model.ResultModel;
import com.moehu.back.model.response.OpusInfoResponseModel;
import com.moehu.back.model.response.PagingResponseModel;
import com.moehu.back.service.impl.OpusServiceImpl;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping(value = "/opus")
@AdminRestController
@Api(tags = "【管理后台】Opus 作品相关接口")
public class AdminOpusController {

    @Autowired
    OpusServiceImpl opusService;

    @UserLoginToken
    @ApiOperation(value="作品审核接口", notes="作品审核接口，用于作品的审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "opus_title", value = "作品标题", required = false, dataType = "String"),
            @ApiImplicitParam(name = "opus_status", value = "作品的审核状态。等待审核0，审核驳回-1，审核通过1", required = false, dataType = "Number"),
            @ApiImplicitParam(name = "opus_type", value = "作品的分类，推荐1，排行2，关注3", required = false, dataType = "Number"),
            @ApiImplicitParam(name = "opus_original", value = "作品是否原创 ，1原创，0 非原创", required = false, dataType = "Number"),
            @ApiImplicitParam(name = "page", value = "请求的页数", required = true, dataType = "Number", defaultValue="1"),
            @ApiImplicitParam(name = "count", value = "每页作品数，默认15", required = true, dataType = "Number", defaultValue="15"),
    })

    @PostMapping("/OpusAudit")
    public ResultModel<PagingResponseModel<List<OpusModel>>> OpusAudit(@RequestBody Map<String, String> opus) {
        return opusService.OpusAudit(opus);
    }

    @UserLoginToken
    @ApiOperation(value="作品详情", notes="查看作品的详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "opus_id", value = "作品的id", required = true, dataType = "Number")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "请求成功"),
            @ApiResponse(code = 500, message = "缺少token，请登录"),
            @ApiResponse(code = 500, message = "无效token，请勿伪造token"),
            @ApiResponse(code = 500, message = "用户不存在，请重新登录")
    })
    @PostMapping("/OpusInfo")
    public ResultModel<OpusInfoResponseModel> OpusInfo(@RequestBody Map<String, Integer> Opus) {
        return opusService.getOpusInfo(Opus.get("opus_id"), "static/admin");
    }


    @UserLoginToken
    @ApiOperation(value="通过 & 拒绝 审核接口", notes="作品审核接口，用于作品的通过 & 拒绝 审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "opus_id", value = "作品的id", required = true, dataType = "Number"),
            @ApiImplicitParam(name = "opus_status", value = "通过审核传：1，拒绝通过传：-1", required = true, dataType = "Number")
    })

    @PostMapping("/Approved")
    public ResultModel<String> Approved(@RequestBody Map<String, Integer> opus) {
        return opusService.Approved(opus);
    }
}
